ACLOCAL_AMFLAGS = -I m4

# FIXME: These should be enabled once the code is safe for them. That requires
# some fairly big refactoring though, which can wait.
# AM_CFLAGS += -Wshadow -Wstrict-aliasing=2

# FIXME: make docs work with distcheck
DISTCHECK_CONFIGURE_FLAGS = --disable-docs --enable-post-processing

EXTRA_DIST = $(NULL)
CLEANFILES = $(NULL)

confdir = $(sysconfdir)/janus
conf_DATA = conf/janus.jcfg.sample

plugindir = $(libdir)/janus/plugins
transportdir = $(libdir)/janus/transports
eventdir = $(libdir)/janus/events
loggerdir = $(libdir)/janus/loggers

SUBDIRS = src html
dist_html_DATA = README.md

demosdir = $(datadir)/janus/demos
demos_DATA = $(NULL)

jsmodulesdir = $(datadir)/janus/javascript
jsmodules_DATA = html/janus.js

%.sample: %.sample.in
	$(MKDIR_P) $(@D)
	$(AM_V_GEN) sed -e "\
	    s|[@]confdir[@]|$(confdir)|;\
	    s|[@]plugindir[@]|$(plugindir)|;\
	    s|[@]transportdir[@]|$(transportdir)|;\
	    s|[@]eventdir[@]|$(eventdir)|;\
	    s|[@]loggerdir[@]|$(loggerdir)|;\
	    s|[@]recordingsdir[@]|$(recordingsdir)|;\
	    s|[@]demosdir[@]|$(demosdir)|;\
	    s|[@]streamdir[@]|$(streamdir)|; \
	    s|[@]luadir[@]|$(luadir)|; \
	    s|[@]duktapedir[@]|$(duktapedir)|" \
	$< > $@ || rm $@

EXTRA_DIST += conf/janus.jcfg.sample.in
CLEANFILES += conf/janus.jcfg.sample


##
# Fuzzers checking
##

check-fuzzers: FORCE
	CC=$(CC) SKIP_JANUS_BUILD=1 LIB_FUZZING_ENGINE=fuzzers/standalone.o ./fuzzers/build.sh
	./fuzzers/run.sh rtcp_fuzzer out/rtcp_fuzzer_seed_corpus
	./fuzzers/run.sh rtp_fuzzer out/rtp_fuzzer_seed_corpus
	./fuzzers/run.sh sdp_fuzzer out/sdp_fuzzer_seed_corpus

.PHONY: FORCE
FORCE:

##
# Docs
##

if ENABLE_DOCS
SUBDIRS += docs
endif

##
# JavaScript module flavours for janus.js
##

if ENABLE_JAVASCRIPT_ES_MODULE
jsmodules_DATA += npm/bundles/janus.es.js
endif

if ENABLE_JAVASCRIPT_UMD_MODULE
jsmodules_DATA += npm/bundles/janus.umd.js
endif

if ENABLE_JAVASCRIPT_IIFE_MODULE
jsmodules_DATA += npm/bundles/janus.iife.js
endif

if ENABLE_JAVASCRIPT_COMMON_JS_MODULE
jsmodules_DATA += npm/bundles/janus.cjs.js
endif

EXTRA_DIST += $(jsmodules_DATA)

if ENABLE_JAVASCRIPT_MODULES

npm/node_modules/rollup/bin/rollup: npm/package.json
	cd npm && $(NPM) install && touch node_modules/rollup/bin/rollup

npm/bundles/janus.%.js: html/janus.js npm/node_modules/rollup/bin/rollup npm/rollup.config.js npm/module.js
	cd npm && $(NPM) run rollup -- --o $(patsubst npm/%,%,$@) --f $*

endif

##
# Configuration
##

configs:
	$(MKDIR_P) $(DESTDIR)$(confdir)
	$(foreach config,$(conf_DATA),cp "$(CURDIR)/$(config)" "$(DESTDIR)$(confdir)/$(notdir $(basename $(config) .sample))";)
	$(MAKE) -C src configs

##
# Extra cleanup
##

clean-local:
	-rm -f docs/doxygen_sqlite3.db
